package cn.ultrarisk.scadmin.manager.util;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * IOUtil
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2013-11-11
 * @since V1.0
 */
public class IOUtil extends FileUtils {
    private static final Logger LOG = LoggerFactory.getLogger(IOUtil.class);

    public static String in2Str(InputStream in, String encoding) {
        if (in == null) {
            return null;
        }

        StringBuffer sb = new StringBuffer();
        try {
            InputStreamReader reader = new InputStreamReader(in, encoding);
            int tmp = -1;
            char temp;
            while ((tmp = reader.read()) != -1) {
                temp = (char) tmp;
                sb.append(temp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return sb.toString();
    }
}
